\IfFileExists{footnote.sty}{\usepackage{footnote}\makesavenoteenv{longtable}}{}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\usepackage[bf,singlelinecheck=off]{caption}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{csquotes}


\usepackage[framemethod=default]{mdframed} % Required for creating the definition box

% temp box
\newmdenv[skipabove=7pt,
skipbelow=7pt,
rightline=false,
leftline=false,
topline=false,
bottomline=false,
innerleftmargin=5pt,
innerrightmargin=5pt,
innertopmargin=0pt,
leftmargin=0cm,
rightmargin=0cm,
linewidth=4pt,
innerbottommargin=0pt]{tBox}

%\usepackage[bottom]{footmisc}
%\usepackage{etoolbox}
\newtoggle{inshade}
\togglefalse{inshade}

\pretocmd{\footnote}{\iftoggle{inshade}{\stepcounter{footnote}}{\relax}}{}{}


\renewenvironment{quote}{\savenotes\begin{tBox}\begin{shaded*}\toggletrue{inshade}\renewcommand{\thempfootnote}{\arabic{footnote}}}{\end{shaded*}\end{tBox}\togglefalse{inshade}
  \spewnotes}
\let\oldhref\href
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}

\renewcommand{\textfraction}{0.05}
\renewcommand{\topfraction}{0.8}
\renewcommand{\bottomfraction}{0.8}
\renewcommand{\floatpagefraction}{0.75}

\makeatletter

\makeatletter
\newenvironment{kframe}{%
\medskip{}
\setlength{\fboxsep}{.8em}
 \def\at@end@of@kframe{}%
 \ifinner\ifhmode%
  \def\at@end@of@kframe{\end{minipage}}%
  \begin{minipage}{\columnwidth}%
 \fi\fi%
 \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
 \colorbox{shadecolor}{##1}\hskip-\fboxsep
     % There is no \\@totalrightmargin, so:
     \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
 \MakeFramed {\advance\hsize-\width
   \@totalleftmargin\z@ \linewidth\hsize
   \@setminipage}}%
 {\par\unskip\endMakeFramed%
 \at@end@of@kframe}
\makeatother

\renewenvironment{Shaded}{\begin{kframe}}{\end{kframe}}

\usepackage{makeidx}
\makeindex

\urlstyle{tt}

\usepackage[hang,flushmargin]{footmisc}

\usepackage{amsthm}
\makeatletter
\def\thm@space@setup{%
  \thm@preskip=8pt plus 2pt minus 4pt
  \thm@postskip=\thm@preskip
}
\makeatother

% Handle glossary links specially.
\newcommand{\gref}[2]{\hyperlink{#2}{\textbf{#1}}}

% Allow box-drawing characters
% See https://tex.stackexchange.com/questions/281368/print-box-drawing-characters-with-pdflatex
% and pg 185 of http://tug.ctan.org/info/symbols/comprehensive/symbols-a4.pdf
\usepackage{pmboxdraw}
\usepackage{newunicodechar}
\newunicodechar{│}{\textSFxi}
\newunicodechar{└}{\textSFii}
\newunicodechar{├}{\textSFviii}
\newunicodechar{─}{\textSFx}

\frontmatter
